package com.anxin.registerManagement.service;

import cn.hutool.core.util.ObjectUtil;
import com.anxin.registerManagement.bean.jo.PageJo;
import com.anxin.registerManagement.bean.persist.Permission;
import com.anxin.registerManagement.mapper.PermissionMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 叶前呈
 * @date 2022/1/31 13:27
 */
@Service
public class PermissionServcie {

    @Autowired
    PermissionMapper permissionMapper;

    /**
     * 查询权限
     */
    public PageInfo<Permission> getPermissionList(PageJo pageJo) {
        if (!ObjectUtil.isEmpty(pageJo.getPageNum()) && !ObjectUtil.isEmpty(pageJo.getPageSize())) {
            PageHelper.startPage(pageJo.getPageNum(), pageJo.getPageSize());
        }
        QueryWrapper<Permission> permissionQueryWrapper = new QueryWrapper<>();
        return new PageInfo<>(permissionMapper.selectList(permissionQueryWrapper));
    }

    /**
     * 获取所有权限
     */
    public List<Permission> getAllPermission() {
        return permissionMapper.selectList(null);
    }
}
